<template>
  <div v-loading="loading" class="app-container">
    <div class="search-box">
      <div class="search-form">
        <el-form ref="searchForm" :inline="true" :model="searchForm">
          <el-form-item label="任职名称" prop="name">
            <el-input v-model="searchForm.name" maxlength="250" autocomplete="off" />
          </el-form-item>
          <el-form-item label="任职类型" prop="type">
            <el-select v-model="searchForm.type" clearable style="width:140px;">
              <el-option
                v-for="item in typeOptions"
                :key="item.code"
                :label="item.name"
                :value="item.code"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="onSearch">查询</el-button>
            <el-button icon="el-icon-remove-outline" title="重置" @click="resetSearchForm" />
          </el-form-item>
        </el-form>
      </div>
      <div class="toolbar-box clearfix">
        <el-button type="primary" icon="el-icon-circle-plus" @click="add">新增</el-button>
      </div>
    </div>

    <el-table
      ref="multipleTable"
      stripe
      :data="tableData"
      border
      class="table"
    >
      <el-table-column prop="applyName" label="申请标题" />
      <el-table-column prop="applicantName" label="申请人" />
      <el-table-column prop="applyTime" label="申请日期" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.applyTime | parseTime("{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="任职名称" />
      <el-table-column prop="typeName" label="任职类型" />
      <el-table-column prop="organizationt" label="任职单位" width="160" />
      <el-table-column prop="approveName" label="审批人" />
      <el-table-column prop="approveTime" label="审批日期" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.approveTime | parseTime("{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="approveComment" label="审批意见" />
      <el-table-column prop="statusName" label="状态" />
      <el-table-column label="操作" width="150" align="left">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status===1" type="text" icon="el-icon-edit" @click="handleEdit(scope.row.id)">修改</el-button>
          <el-button v-if="scope.row.status===3" type="text" icon="el-icon-edit" @click="reApply(scope.row.id)">重新提交</el-button>
          <el-button v-if="scope.row.status===1" type="text" icon="el-icon-delete" class="red" @click="handleDelete(scope.row.id,scope.row)">取消</el-button>
          <el-button v-if="scope.row.status!==1" type="text" icon="el-icon-view" @click="handleShow(scope.row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" :page.sync="curPage" :limit.sync="limit" @pagination="getList" />
    <!--表单组件-->
    <eForm ref="eform" />
    <sForm ref="sform" />
  </div>
</template>

<script>
import request from '@/utils/request'
import Pagination from '@/components/Pagination'
import eForm from './form'
import sForm from '../list/show'
export default {
  name: 'SocialJobApply',
  components: { Pagination, eForm, sForm },
  data() {
    return {
      curPage: 1,
      limit: 5,
      total: 0,
      loading: true,
      downloadLoading: false,
      orderByClause: null,
      tableData: [],
      typeOptions: [],
      searchForm: {
        name: '',
        type: '',
        applicantId: ''
      }
    }
  },
  created() {
    this.getTypeOptions()
    this.getList()
  },
  methods: {
    getTypeOptions() {
      request({ url: '/sys/dirtionary/getDirtionaryItems', params: { dirtionary: 'SOCIALJOBTYPE' }, method: 'get' })
        .then(data => {
          this.typeOptions = data
        })
    },
    getList() {
      this.loading = true
      const param = {}
      const queryPage = {}
      queryPage.limit = this.limit
      queryPage.offset = this.limit * (this.curPage - 1)
      param.page = queryPage
      if (this.orderByClause && this.orderByClause.trim() !== '') {
        param.orderByClause = this.orderByClause
      }
      this.copyNotBlankField(this.searchForm, param)
      request({ url: '/edu/socialjob/findSelf', method: 'post', data: param })
        .then(res => {
          this.loading = false
          this.tableData = res.rows
          this.total = res.total
          this.curPage = res.pageNumber
        })
        .catch(e => {
          this.loading = false
          this.$message.error('查询出错')
        })
    },
    onSearch() {
      this.getList()
    },
    resetSearchForm() {
      this.$refs['searchForm'].resetFields()
    },
    add() {
      this.$refs.eform.add()
    },
    handleEdit(id) {
      this.$refs.eform.edit(id)
    },
    handleDelete(id, row) {
      this.$confirm('此操作将取消[' + row.name + ']申请, 是否继续?', '确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.doDelete(id)
        })
    },
    reApply(id) {
      this.$refs.eform.reApply(id)
    },
    doDelete(id) {
      this.loading = true
      request({ url: '/edu/socialjob/cancel', method: 'get', params: { id: id }})
        .then(res => {
          this.loading = false
          this.getList()
        })
        .catch(e => {
          this.loading = false
          this.$message.error('取消出错！' + e.message ? e.message : '')
        })
    },
    handleShow(id) {
      this.$refs.sform.show(id)
    }

  }
}
</script>
